//
// Created by dave on 18-7-29.
//

#pragma once
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>

class data_pack;

unsigned short read_word(std::vector<unsigned char>& data, std::size_t start);

unsigned int read_dword(std::vector<unsigned char>& data, std::size_t start);

std::string read_bcd(std::vector<unsigned char>& data, std::size_t start, std::size_t size);

void write_word(std::vector<unsigned char>& data, unsigned short word);

void write_dword(std::vector<unsigned char>& data, unsigned int dword);

std::vector<unsigned char> get_bcd_bytes(const std::string& data);

void write_bcd(std::vector<unsigned char>& buf, const std::string& data);

unsigned char checksum(std::vector<unsigned char>& buf);

data_pack decode_data_pack(const unsigned char* buf, std::size_t start, std::size_t stop);

std::string gbk2utf8(const std::string& str);

std::string utf8_gbk(const std::string& str);

time_t parse_time(const std::string& time);